home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fwcp / src / fmr.c < prev    next >
Text File  |  1995-03-09  |  5KB  |  231 lines

  1. #include    <stdio.h>
  2. #include    <dos.h>
  3.  
  4. #define    ERR    (-1)
  5. #define    FALSE    0
  6. #define    TRUE    1
  7.  
  8. #define    LIN_SIZ    80
  9. #define    SCR_SIZ    24
  10.  
  11. static    struct CONS_TBL {
  12.         char    cur_type;
  13.         short    cur_line;
  14.         char    cur_disp;
  15.         short    cur_pont;
  16.         char    def_attr[4];
  17.         char    vram_code[SCR_SIZ][LIN_SIZ];
  18.         long    vram_attr[SCR_SIZ][LIN_SIZ];
  19.     } console;
  20.  
  21.     char    *stralloc(char *str);
  22.  
  23. void    Console_Save()
  24. {
  25.     union REGS regs;
  26.     struct SREGS seg;
  27.     union {
  28.     char far *p;
  29.     short     s[2];
  30.     } pp;
  31.     struct {
  32.     char far *code;
  33.     long far *attr;
  34.     } tbl;
  35.  
  36.     regs.h.ah = 0x0A;
  37.     int86(0x91,®s,®s);
  38.     console.cur_type = regs.h.al;
  39.     console.cur_line = regs.x.dx;
  40.  
  41.     regs.h.ah = 0x0C;
  42.     int86(0x91,®s,®s);
  43.     console.cur_disp = regs.h.al;
  44.  
  45.     regs.h.ah = 0x0E;
  46.     int86(0x91,®s,®s);
  47.     console.cur_pont = regs.x.dx;
  48.  
  49.     pp.p = (char far *)(console.def_attr);
  50.     regs.h.ah = 0x12;
  51.     regs.x.di = pp.s[0];
  52.     seg.ds    = pp.s[1];
  53.     int86x(0x91,®s,®s,&seg);
  54.  
  55.     tbl.code = (char far *)(console.vram_code);
  56.     tbl.attr = (long far *)(console.vram_attr);
  57.     pp.p = (char far *)(&tbl);
  58.     regs.h.ah = 0x16;
  59.     regs.h.al = 1;
  60.     regs.h.dh = 1;
  61.     regs.h.dl = 1;
  62.     regs.h.bh = SCR_SIZ;
  63.     regs.h.bl = LIN_SIZ;
  64.     regs.x.di = pp.s[0];
  65.     seg.ds    = pp.s[1];
  66.     int86x(0x91,®s,®s,&seg);
  67. }
  68. void    Console_Load()
  69. {
  70.     union REGS regs;
  71.     struct SREGS seg;
  72.     union {
  73.     char far *p;
  74.     short     s[2];
  75.     } pp;
  76.     struct {
  77.     char far *code;
  78.     long far *attr;
  79.     } tbl;
  80.  
  81.     regs.h.ah = 0x09;
  82.     regs.h.al = console.cur_type;
  83.     regs.x.dx = console.cur_line;
  84.     int86(0x91,®s,®s);
  85.  
  86.     regs.h.ah = 0x0B;
  87.     regs.h.al = console.cur_disp;
  88.     int86(0x91,®s,®s);
  89.  
  90.     regs.h.ah = 0x0D;
  91.     regs.x.dx = console.cur_pont;
  92.     int86(0x91,®s,®s);
  93.  
  94.     pp.p = (char far *)(console.def_attr);
  95.     regs.h.ah = 0x11;
  96.     regs.x.di = pp.s[0];
  97.     seg.ds    = pp.s[1];
  98.     int86x(0x91,®s,®s,&seg);
  99.  
  100.     tbl.code = (char far *)(console.vram_code);
  101.     tbl.attr = (long far *)(console.vram_attr);
  102.     pp.p = (char far *)(&tbl);
  103.     regs.h.ah = 0x15;
  104.     regs.h.al = 1;
  105.     regs.h.dh = 1;
  106.     regs.h.dl = 1;
  107.     regs.h.bh = SCR_SIZ;
  108.     regs.h.bl = LIN_SIZ;
  109.     regs.x.di = pp.s[0];
  110.     seg.ds    = pp.s[1];
  111.     int86x(0x91,®s,®s,&seg);
  112. }
  113.  
  114. #define    DEV_LOCAL    0x00
  115. #define    DEV_NET        0x10
  116. #define    DEV_FDD        0x20
  117. #define    DEV_EXTFDD    0x30
  118. #define    DEV_HDD        0x40
  119. #define    DEV_MO        0x50
  120. #define    DEV_RAM        0x60
  121. #define    DEV_CD        0x70
  122.  
  123. static    unsigned char    drv_unit[26] = {
  124.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  125.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  126.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  127.     0xFF, 0xFF };
  128. static    char    *drv_name[] = {
  129.     "Local Disk",
  130.     "NetWork Device",
  131.     "Flopy Disk      %d",
  132.     "Ext Flopy Disk  %d",
  133.     "Hard Disk Drive %d",
  134.     "MO Disk Drive   %d",
  135.     "RAM Disk",
  136.     "Compact Disc ROM",
  137.     NULL
  138.     };
  139. static    char    *drv_vct[27];
  140.  
  141. void    DSKINIT()
  142. {
  143.     int n, i;
  144.     union REGS regs;
  145.     struct SREGS seg;
  146.     union {
  147.     char far *p;
  148.     short     s[2];
  149.     } pp;
  150.     unsigned char tmp[200];
  151.  
  152.     pp.p = (char far *)(&tmp);
  153.     regs.h.ah = 0x00;
  154.     regs.x.di = pp.s[0];
  155.     seg.ds    = pp.s[1];
  156.     int86x(0x8E, ®s, ®s, &seg);
  157.  
  158.     if ( regs.h.ah == 0 ) {
  159.     for ( n = 0 ; n < 16 ; n++ ) {
  160.         switch(tmp[0x30 + n * 2]) {
  161.         case 0x00:    /* FDD */
  162.         drv_unit[n] = DEV_FDD | tmp[0x31 + n * 2];
  163.         break;
  164.         case 0x01:    /* ExtFDD */
  165.         drv_unit[n] = DEV_EXTFDD | tmp[0x31 + n * 2];
  166.         break;
  167.         case 0x02:    /* SCSI */
  168.         regs.x.ax = 0x4408;
  169.         regs.h.bl = n + 1;
  170.         intdos(®s, ®s);
  171.         if ( regs.x.cflag == 0 && regs.x.ax == 0 )
  172.             drv_unit[n] = DEV_MO | tmp[0x31 + n * 2] >> 4;
  173.         else
  174.             drv_unit[n] = DEV_HDD | tmp[0x31 + n * 2] >> 4;
  175.         break;
  176.         case 0x03:    /* RAM */
  177.         drv_unit[n] = DEV_RAM;
  178.         break;
  179.         case 0x04:    /* MDC */
  180.         drv_unit[n] = DEV_HDD;
  181.         break;
  182.         case 0xFF:    /* no dev */
  183.         drv_unit[n] = 0xFF;
  184.         break;
  185.         default:    /* local dev */
  186.         drv_unit[n] = 0x00;
  187.         break;
  188.         }
  189.     }
  190.     }
  191.  
  192.     for ( n = 0 ; n < 26 ; n++ ) {
  193.     if ( drv_unit[n] != 0xFF )
  194.         continue;
  195.     regs.x.ax = 0x4409;
  196.     regs.h.bl = n + 1;
  197.     intdos(®s, ®s);
  198.     if ( regs.x.cflag == 0 ) {
  199.         if ( (regs.x.dx & 0x1000) != 0 )
  200.         drv_unit[n] = DEV_NET;
  201.         else
  202.         drv_unit[n] = DEV_LOCAL;
  203.     }
  204.     }
  205.  
  206.     for ( n = i = 0 ; n < 26 ; n++ ) {
  207.     if ( drv_unit[n] != 0xFF ) {
  208.         sprintf(tmp, "%c: ", n + 'A');
  209.         sprintf(tmp + 3, drv_name[drv_unit[n] >> 4], drv_unit[n] & 0x0F);
  210.         drv_vct[i++] = stralloc(tmp);
  211.     }
  212.     }
  213.     drv_vct[i] = NULL;
  214. }
  215. int    drv_menu(int x, int y, int drv)    /* A=1, B=2 ... */
  216. {
  217.     int n, no = 0;
  218.  
  219.     for ( n = 0 ; drv_vct[n] != NULL ; n++ ) {
  220.     if ( (drv + 'A' - 1) == drv_vct[n][0] ) {
  221.         no = n;
  222.         break;
  223.     }
  224.     }
  225.  
  226.     if ( (n = menu(x, y, no, drv_vct)) < 0 )
  227.     return drv;
  228.  
  229.     return (drv_vct[n][0] - 'A' + 1);
  230. }
  231.